package com.sdonkey.score.controller;

import com.alibaba.fastjson.JSONObject;
import com.sdonkey.score.bean.LoginReturnBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;

public class BaseController {
    public Logger logger = LoggerFactory.getLogger(BaseController.class);

    public LoginReturnBean getCurrentUser(HttpServletRequest request){

        return (LoginReturnBean)request.getAttribute("advertiser");
    }


    public JSONObject createError(String code, String msg){
        JSONObject result = new JSONObject();
        JSONObject error = new JSONObject();
        error.put("code", code);
        error.put("msg", msg);
        result.put("error", error);
        return error;
    }

    public JSONObject success(JSONObject result){
        JSONObject info = new JSONObject();
        info.put("result", result);
        return info;
    }
    public JSONObject error(JSONObject error){
        JSONObject info = new JSONObject();
        info.put("error", error);
        return info;
    }
}
